<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .progress {
        border: solid;
        padding: 5px;
        margin: 10px;
      }
      .progress .bar {
        height: 10px;
        width: 0%;
        background: greenyellow;
      }
    </style>
  </head>
  <body>
    <h1>HELLO Index</h1>

    <input type="file" id="uploadInput" />
    <button onclick="upload(document.getElementById('uploadInput'))">
      保存
    </button>
    <div class="progress">
      <div class="bar" id="progressBar"></div>
    </div>
    <script src="./axios.min.js"></script>
    <script>
      const request = axios.create({
        baseURL: "http://127.0.0.1:8090/api/collections",
      });
      function upload(el) {
        const file = el.files[0];
        const data = new FormData();
        data.append("docname", "doc1");
        data.append("file", file);
        request
          .post("/documents/records", data, {
            onUploadProgress(e) {
              console.log((e.loaded / e.total) * 100 + "%");
              progressBar.style.width = (e.loaded / e.total) * 100 + "%";
            },
          })
          .then((data) => {
            progressBar.style.width = "100%";
          });
      }
    </script>
  </body>
</html>
